<extend name="Base/common" />
<block name="body">
  <div class="span9 page_message">
    <section id="contents"> <include file="Addons/_nav" />
      <div class="cf" style="width:500px">
        <div class="fl">
          <select name="cate" id="cate_select" style="width:150px">
            <option value="0" >全部分类</option>
            <volist name="cate" id="vo"> <option value="{$vo.id}" 
              <if condition="$_GET[cate_id]==$vo[id]">selected="selected"</if>
              >{$vo.title}
              
              </option>
            </volist>
          </select>
        </div>
        <!-- 高级搜索 -->
        <if condition="$search_button">
          <div class="search-form cf">
            <div class="sleft" style="margin-left:20px">
              <php> $search_url || $search_url = addons_url($_REQUEST ['_addons'].'://'.$_REQUEST ['_controller'].'/add',array('model'=>$model['name']));</php>
              <input type="text" name="{$model['search_key']|default='title'}" class="search-input" value="{:I('title')}" placeholder="请输入关键字">
              <a class="sch-btn" href="javascript:;" id="search" url="{$search_url}"><i class="btn-search"></i></a> </div>
          </div>
        </if>
      </div>
      
      <!-- 数据列表 -->
      <div class="data-table fl" style="width:400px">
        <div class="data-table table-striped">
          <table>
            <!-- 表头 -->
            <thead>
              <tr>
                <th>标题(可拖动排序)</th>
                <th>操作</th>
              </tr>
            </thead>
            
            <!-- 列表 -->
            <tbody>
              <volist name="list_data" id="vo">
                <tr>
                  <td id="news_{$vo.id}">{$vo.title}
                    <input type="hidden" value="{$vo.id}" name="ids[]"></td>
                  <td><a href="javascript:void(0);" onClick="select_news({$vo.id})">选择</a></td>
                </tr>
              </volist>
            </tbody>
          </table>
        </div>
        <div class="page"> {$_page|default=''} </div>
      </div>
      <form id="form" action="{$post_url}" method="post" class="form-horizontal">
        <div class="data-table fr" style="width:400px">
          <div class="data-table table-striped">
            <table>
              <!-- 表头 -->
              <thead>
                <tr>
                  <th>已选择的图文标题(可拖动排序)</th>
                  <th>操作</th>
                </tr>
              </thead>
              
              <!-- 列表 -->
              <tbody id="select_news">
                <volist name="select_news" id="vo">
                  <tr id="select_tr_{$vo.id}" rel="{$vo.id}" class="sltr">
                    <td>{$vo.title}
                      <input type="hidden" name="ids[]" value="{$vo.id}"></td>
                    <td><a onclick="del_news({$vo.id})" href="javascript:void(0);">删除</a></td>
                  </tr>
                </volist>
              </tbody>
            </table>
          </div>
          <div class="form-item cf">
            <label class="item-label">关键词<span class="check-tips"> </span></label>
            <div class="controls">
              <input type="text" value="{$mult.keyword}" name="keyword" class="text input-large">
            </div>
          </div>
          <div class="form-item cf">
            <label class="item-label">关键词类型<span class="check-tips"> </span></label>
            <div class="controls">
              <select name="keyword_type">
                <option value="0" <eq name="mult.keyword_type" value="0">selected="selected"</eq> >完全匹配 </option>
                <option value="1" <eq name="mult.keyword_type" value="1">selected="selected"</eq>>左边匹配 </option>
                <option value="2" <eq name="mult.keyword_type" value="2">selected="selected"</eq>>右边匹配 </option>
                <option value="3" <eq name="mult.keyword_type" value="3">selected="selected"</eq>>模糊匹配 </option>
              </select>
            </div>
          </div>
          <div class="form-item cf">
            <button class="home_btn submit-btn" id="submit" type="submit" target-form="form-horizontal">保 存</button>
            <a class="home_btn btn-return" href="javascript:;">返 回</a> </div>
        </div>
      </form>
    </section>
  </div>
</block>
<block name="script"> 
  <script type="text/javascript" src="__STATIC__/jquery.dragsort-0.5.1.min.js?v={:SITE_VERSION}"></script> 
  <script type="text/javascript">
function select_news(id){
	var count = 0;
	var isExist = false;
	$('.sltr').each(function() { 
	   if( $(this).attr('rel')==id )  {
		   isExist = true;
	   }
	   count +=1;
	});
	if(isExist){
		return false;
	}	
	if(count>=9){
	    alert('同时最多不能超过9个');	
		return false;
	}
	
	var html = $('#news_'+id).html();
	html = '<tr class="sltr" rel="'+id+'" id="select_tr_'+id+'"><td>'+html+'</td><td><a href="javascript:void(0);" onClick="del_news('+id+')">删除</a></td></tr>';
	$('#select_news').append(html);
	dragsort();
}
function del_news(id){
	var html = $('#select_tr_'+id).remove();
	dragsort();
}
function dragsort(){
	$("#select_news").dragsort({
          itemSelector: "tr", dragSelector: "tr", dragBetween: true
	 });	
}
function seach(){
	var url = $("#search").attr('url');
	var query  = $('.search-form').find('input').serialize();console.log(query);
	query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');console.log(query);
	query = query.replace(/^&/g,'');console.log(query);
	
	var cate_id = $("#cate_select").val();
	query += '&cate_id='+cate_id;
	
	if( url.indexOf('?')>0 ){
		url += '&' + query;
	}else{
		url += '?' + query;
	}
	window.location.href = url;	
}
$(function(){
	//搜索功能
	$("#search").click(function(){ seach();	});
	//下拉选择
	$("#cate_select").change(function(){ seach();	});	

    //回车自动提交
    $('.search-form').find('input').keyup(function(event){
        if(event.keyCode===13){
            $("#search").click();
        }
    });
	
	dragsort();
})
</script> 
</block>
